﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Windows.Controls;

namespace Cloak.Mvvm.Navigation
{
	/// <summary>
	/// A page to which a navigation context has navigated
	/// </summary>
	public class NavigatedPage
	{
		private readonly Page _page;

		/// <summary>
		/// Initializes an instance of <see cref="NavigatedPage"/>
		/// </summary>
		/// <param name="uri">The URI of the page</param>
		/// <param name="page">The content of the page</param>
		public NavigatedPage(Uri uri, Page page)
		{
			Contract.Requires(uri != null);
			Contract.Requires(page != null);

			Uri = uri;
			_page = page;
		}

		/// <summary>
		/// Gets the URI of the page
		/// </summary>
		public Uri Uri { get; private set; }

		/// <summary>
		/// Gets the type of the page
		/// </summary>
		public Type Type
		{
			get { return _page.GetType(); }
		}

		/// <summary>
		/// Gets the parameters passed to the page
		/// </summary>
		public IDictionary<string, string> Parameters
		{
			get { return _page.NavigationContext.QueryString; }
		}

		/// <summary>
		/// Sets the data context of the page to the specified view model
		/// </summary>
		/// <param name="model">The view model to be set as the data context of the page</param>
		public void SetModel(ViewModel model)
		{
			Contract.Requires(model != null);

			_page.DataContext = model;
		}
	}
}